package com.atguigu.gmall.publisher.mapper;

import com.atguigu.gmall.publisher.beans.KeywordStats;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 关键词统计Mapper
 *
 * @author lvbingbing
 * @date 2022-07-07 11:13
 */
public interface KeywordStatsMapper {

    @Select(" select " +
            " keyword, " +
            " sum(keyword_stats_2021.ct * multiIf(source = 'SEARCH', 10, source = 'ORDER', 5, source = 'CART', 2, source = 'CLICK', 1, 0)) as ct " +
            " from keyword_stats_2021 " +
            " where toYYYYMMDD(stt) = #{date} " +
            " group by keyword " +
            " order by ct desc " +
            " limit #{limit} ")
    List<KeywordStats> selectKeywordStats(@Param("date") Integer date, @Param("limit") Integer limit);
}
